import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Input, Modal, Radio } from 'antd';
import React from 'react';

const FormItem = Form.Item;
const { TextArea } = Input;

const CreateForm = props => {
  const { createModalVisible, form, onSubmit: handleAdd, onCancel } = props;
  const okHandle = () => {
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      form.resetFields();
      handleAdd(fieldsValue);
    });
  };
  const formLayout = {
    labelCol: {
      span: 5,
    },
    wrapperCol: {
      span: 15,
    },
  };

  return (
    <Modal
      destroyOnClose={true}
      title="新建贵宾室价格"
      visible={createModalVisible}
      onOk={okHandle}
      onCancel={() => onCancel()}
    >
      <FormItem {...formLayout} label="产品名称">
        {form.getFieldDecorator('name', {
          rules: [
            {
              required: true,
              message: '请输入产品名称！',
            },
            {
              pattern: /^[\u4E00-\u9FA5]{1,8}$/,
              message: '请输入1-8位中文字符！'
            }
          ],
        })(<Input placeholder="请输入" />)}
      </FormItem>
      <FormItem label="产品价格(元)" {...formLayout}>
        {form.getFieldDecorator('price', {
          rules: [
            {
              required: true,
              message: '请输入产品价格！',
            },
            {
              pattern: /^([0]|[1-9][0-9]{0,3})$/,
              message: '请输入1-4位整数！'
            }
          ],
        })(<Input placeholder="请输入" />)}
      </FormItem>
      <FormItem label="产品描述" {...formLayout}>
        {form.getFieldDecorator('desc', {
          rules: [
            {
              required: true,
              message: '请输入产品描述！',
            },
            {
              max: 80,
              message: '请输入1-80位字符！'
            }
          ],
        })(<Input maxLength={80} placeholder="请输入" />)}
      </FormItem>
    </Modal>
  );
};

export default Form.create()(CreateForm);
